﻿Imports System.Data
Imports System.Data.OleDb
Imports DTO

Public Class LoaiVeDao
    Dim provider As New DataProvider

    Public Function LayDanhSachLoaiVe() As DataTable
        Dim sql As String = "SELECT * FROM LOAIVE"
        Return provider.ThucThiCauTruyVan(sql)
    End Function

    Public Function LayDanhSachLoaiVeTheoMaTuyen(ByVal maTuyen As Integer) As DataTable
        Dim sql As String = "SELECT * FROM LOAIVE WHERE MaTuyen = " & maTuyen

        Return provider.ThucThiCauTruyVan(sql)
    End Function


    Public Function ThemLoaiVe(ByVal loaive As LoaiVeDto) As Integer
        Dim sql As String = "INSERT  INTO LOAIVE(MaTuyen, GiaVe) VALUES (?, ?)"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@MaTuyen", loaive.MaTuyen))
        dsParameter.Add(New OleDbParameter("@GiaVe", loaive.GiaVe))

        Return provider.ThucThiTruyVanThuong(sql, dsParameter)
    End Function

    Public Function CapNhatLoaiVe(ByVal loaive As LoaiVeDto) As Integer
        Dim sql As String = "UPDATE LOAIVE SET GiaVe = ? WHERE MaLoaiVe = ?"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@GiaVe", loaive.GiaVe))
        dsParameter.Add(New OleDbParameter("@MaLoaiVe", loaive.MaLoai))

        Return provider.ThucThiTruyVanThuong(sql, dsParameter)
    End Function

    Public Function XoaLoaiVe(ByVal maCanXoa As Long) As Integer
        Dim sql As String = "DELETE FROM LOAIVE WHERE MaLoaiVe = ?"

        Dim dsParameter As New List(Of OleDbParameter)
        dsParameter.Add(New OleDbParameter("@MaLoai", maCanXoa))

        Return provider.ThucThiTruyVanThuong(sql, dsParameter)
    End Function

End Class
